# coding=utf-8
'''
Created on 2013-12-20

@author: sunxiang
'''
from mongoengine import *
from model.user import User
from lib.gravatar import Gravatar

class UserService(object):
    def get_user_by_uuid(self, uuid):
        return User.objects.filter(uuid = uuid)
    
    def get_user_by_username(self, username):
        return User.objects.filter(username = username)
    
    def get_user_by_nickname(self, nickname):
        return User.objects.filter(nickname = nickname)
    
    def get_user_by_email(self, email):
        return User.objects.filter(email = email)
    
    def get_user_gravatar(self, email, size=96):
        gravatar = Gravatar(email)
        return gravatar.get_image(size = size, filetype_extension = False)

    def get_user_by_username_and_password(self, username, password_md5):
        return User.objects.filter(username = username, password = password_md5)
    
    def get_user_by_email_and_password(self, email, password_md5):
        return User.objects.filter(email = email, password = password_md5)
        
    def save(self, user):
        user.save()